package cn.wolfcode.wolf2w.util;

import org.springframework.util.StringUtils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class AssertUtil {
    public static void hasLength(String val,String msg){
        /**
         * 判断传入的值是否为空,如果为空抛出指定的信息
         */
        if(!StringUtils.hasLength(val)){
            throw new LogicException(msg);
        }

    }

    public static void testPhone(String val,String msg) {
        Pattern pat = Pattern.compile("^[1][3578][0-9]{9}$");
        Matcher mat = pat.matcher(val);
        boolean b = mat.find();
        if(!b){
            throw new LogicException(msg);
        }
    }

    public static void isEuqal(String str1,String str2,String msg){
        if(str1!=null&&str2!=null){
            boolean equals = str1.equals(str2);
            if (!equals){
                throw new LogicException(msg);
            }
        }else{
            throw new LogicException("参数不能为空");
        }
    }

}
